/*     */ package com.zimbra.cs.account.accesscontrol;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.DistributionListBy;
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.GuestAccount;
/*     */ import com.zimbra.cs.account.NamedEntry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.soap.admin.type.GranteeSelector;
/*     */ import com.zimbra.soap.admin.type.GranteeSelector.GranteeBy;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public enum GranteeType
/*     */ {
/*  37 */   GT_USER("usr", com.zimbra.soap.type.GranteeType.usr, (short)67), 
/*  38 */   GT_GROUP("grp", com.zimbra.soap.type.GranteeType.grp, (short)69), 
/*  39 */   GT_EXT_GROUP("egp", com.zimbra.soap.type.GranteeType.egp, (short)5), 
/*  40 */   GT_AUTHUSER("all", com.zimbra.soap.type.GranteeType.all, (short)16), 
/*  41 */   GT_DOMAIN("dom", com.zimbra.soap.type.GranteeType.dom, (short)73), 
/*     */   
/*  43 */   GT_EXT_DOMAIN("edom", com.zimbra.soap.type.GranteeType.edom, (short)2), 
/*  44 */   GT_GUEST("gst", com.zimbra.soap.type.GranteeType.gst, (short)130), 
/*  45 */   GT_KEY("key", com.zimbra.soap.type.GranteeType.key, (short)130), 
/*  46 */   GT_PUBLIC("pub", com.zimbra.soap.type.GranteeType.pub, (short)32), 
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  59 */   GT_EMAIL("email", com.zimbra.soap.type.GranteeType.email, (short)2);
/*     */   
/*     */   private String mCode;
/*     */   
/*  63 */   private static class GT { static Map<String, GranteeType> sCodeMap = new HashMap();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private GranteeType(String code, com.zimbra.soap.type.GranteeType jaxbGT, short flags)
/*     */   {
/*  71 */     this.mCode = code;
/*  72 */     GT.sCodeMap.put(code, this);
/*  73 */     this.mFlags = flags;
/*  74 */     this.jaxbGranteeType = jaxbGT;
/*     */   }
/*     */   
/*     */   public static GranteeType fromCode(String granteeType) throws ServiceException {
/*  78 */     GranteeType gt = (GranteeType)GT.sCodeMap.get(granteeType);
/*  79 */     if (gt == null) {
/*  80 */       throw ServiceException.PARSE_ERROR("invalid grantee type: " + granteeType, null);
/*     */     }
/*  82 */     return gt;
/*     */   }
/*     */   
/*     */   public com.zimbra.soap.type.GranteeType toJaxb()
/*     */   {
/*  87 */     return this.jaxbGranteeType;
/*     */   }
/*     */   
/*     */   public static GranteeType fromJaxb(com.zimbra.soap.type.GranteeType jaxbGT) {
/*  91 */     for (GranteeType gt : ) {
/*  92 */       if (gt.toJaxb() == jaxbGT) {
/*  93 */         return gt;
/*     */       }
/*     */     }
/*  96 */     throw new IllegalArgumentException("Unrecognised GranteeType:" + jaxbGT);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public String getCode()
/*     */   {
/* 108 */     return this.mCode;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public boolean allowedForAdminRights()
/*     */   {
/* 115 */     return hasFlags((short)1);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public boolean allowSecret()
/*     */   {
/* 122 */     return hasFlags((short)128);
/*     */   }
/*     */   
/*     */   public boolean isZimbraEntry() {
/* 126 */     return hasFlags((short)64);
/*     */   }
/*     */   
/*     */   public boolean needsGranteeIdentity() {
/* 130 */     return (GT_AUTHUSER != this) && (GT_PUBLIC != this);
/*     */   }
/*     */   
/*     */   public boolean hasFlags(short flags) {
/* 134 */     return (flags & this.mFlags) == flags;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private short mFlags;
/*     */   
/*     */ 
/*     */ 
/*     */   private com.zimbra.soap.type.GranteeType jaxbGranteeType;
/*     */   
/*     */ 
/*     */   public static NamedEntry lookupGrantee(Provisioning prov, GranteeType granteeType, GranteeSelector.GranteeBy granteeBy, String grantee, boolean mustFind)
/*     */     throws ServiceException
/*     */   {
/* 150 */     NamedEntry granteeEntry = null;
/*     */     
/* 152 */     switch (granteeType) {
/*     */     case GT_USER: 
/* 154 */       granteeEntry = prov.get(Key.AccountBy.fromString(granteeBy.name()), grantee);
/* 155 */       if ((mustFind) && (granteeEntry == null)) {
/* 156 */         throw AccountServiceException.NO_SUCH_ACCOUNT(grantee);
/*     */       }
/*     */       break;
/*     */     case GT_GROUP: 
/* 160 */       granteeEntry = prov.getGroupBasic(Key.DistributionListBy.fromString(granteeBy.name()), grantee);
/* 161 */       if ((mustFind) && (granteeEntry == null)) {
/* 162 */         throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(grantee);
/*     */       }
/*     */       break;
/*     */     case GT_DOMAIN: 
/* 166 */       granteeEntry = prov.get(Key.DomainBy.fromString(granteeBy.name()), grantee);
/* 167 */       if ((mustFind) && (granteeEntry == null)) {
/* 168 */         throw AccountServiceException.NO_SUCH_DOMAIN(grantee);
/*     */       }
/*     */       break;
/*     */     case GT_GUEST: 
/* 172 */       granteeEntry = new GuestAccount(grantee, null);
/* 173 */       break;
/*     */     
/*     */     case GT_EMAIL: 
/* 176 */       granteeEntry = prov.get(Key.AccountBy.fromString(granteeBy.name()), grantee);
/* 177 */       if (granteeEntry == null)
/*     */       {
/* 179 */         granteeEntry = prov.getGroupBasic(Key.DistributionListBy.fromString(granteeBy.name()), grantee);
/*     */       }
/* 181 */       if (granteeEntry == null) {
/*     */         try
/*     */         {
/* 184 */           ExternalGroup.get(Key.DomainBy.name, grantee, false);
/*     */         }
/*     */         catch (ServiceException e) {}
/*     */       }
/*     */       
/*     */ 
/* 190 */       if (granteeEntry == null)
/*     */       {
/* 192 */         granteeEntry = new GuestAccount(grantee, null);
/*     */       }
/*     */       break;
/*     */     default: 
/* 196 */       throw ServiceException.INVALID_REQUEST("invalid grantee type for lookupGrantee:" + granteeType.getCode(), null);
/*     */     }
/*     */     
/*     */     
/* 200 */     return granteeEntry;
/*     */   }
/*     */   
/*     */   public static NamedEntry lookupGrantee(Provisioning prov, GranteeType granteeType, GranteeSelector.GranteeBy granteeBy, String grantee)
/*     */     throws ServiceException
/*     */   {
/* 206 */     return lookupGrantee(prov, granteeType, granteeBy, grantee, true);
/*     */   }
/*     */   
/*     */   public static NamedEntry lookupGrantee(Provisioning prov, GranteeSelector selector, boolean mustFind) throws ServiceException
/*     */   {
/* 211 */     return lookupGrantee(prov, fromJaxb(selector.getType()), selector.getBy(), selector.getKey(), mustFind);
/*     */   }
/*     */   
/*     */   public static NamedEntry lookupGrantee(Provisioning prov, GranteeSelector selector)
/*     */     throws ServiceException
/*     */   {
/* 217 */     return lookupGrantee(prov, selector, true);
/*     */   }
/*     */   
/*     */ 
/*     */   public static GranteeType determineGranteeType(GranteeType granteeType, GranteeSelector.GranteeBy granteeBy, String grantee, String domainName)
/*     */     throws ServiceException
/*     */   {
/* 224 */     if (granteeType != GT_EMAIL) {
/* 225 */       return granteeType;
/*     */     }
/*     */     
/*     */ 
/* 229 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*     */ 
/* 232 */     if (lookupGrantee(prov, GT_USER, granteeBy, grantee, false) != null) {
/* 233 */       return GT_USER;
/*     */     }
/*     */     
/*     */ 
/* 237 */     if (lookupGrantee(prov, GT_GROUP, granteeBy, grantee, false) != null) {
/* 238 */       return GT_GROUP;
/*     */     }
/*     */     
/*     */     try
/*     */     {
/* 243 */       boolean asAdmin = false;
/* 244 */       if (ExternalGroup.get(Key.DomainBy.name, ZimbraACE.ExternalGroupInfo.encodeIfExtGroupNameMissingDomain(domainName, grantee), asAdmin) != null)
/*     */       {
/* 246 */         return GT_EXT_GROUP;
/*     */       }
/*     */     }
/*     */     catch (ServiceException e) {}
/*     */     
/*     */ 
/*     */ 
/* 253 */     return GT_GUEST;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/accesscontrol/GranteeType.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */